package com.ruoyi.web.controller.pack;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pack.domain.PackProjectWarehouseOperation;
import com.ruoyi.pack.service.IPackProjectWarehouseOperationService;

/**
 * 项目仓库操作权限Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/pack/project")
public class PackProjectWarehouseOperationController extends BaseController
{
    @Autowired
    private IPackProjectWarehouseOperationService packProjectWarehouseOperationService;

    /**
     * 查询项目仓库操作权限列表
     */
    @PreAuthorize("@ss.hasPermi('pack:project:query')")
    @GetMapping("/{projectId}/warehouse/operation/list")
    public TableDataInfo list(@PathVariable("projectId") Long projectId)
    {
        startPage();
        PackProjectWarehouseOperation query = new PackProjectWarehouseOperation();
        query.setProjectId(projectId);
        List<PackProjectWarehouseOperation> list = packProjectWarehouseOperationService.selectPackProjectWarehouseOperationList(query);
        return getDataTable(list);
    }

    /**
     * 获取项目仓库操作权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('pack:project:query')")
    @GetMapping("/{projectId}/warehouse/operation/{projectWarehouseId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId, @PathVariable("projectWarehouseId") Long projectWarehouseId)
    {
        return success(packProjectWarehouseOperationService.selectPackProjectWarehouseOperationByProjectWarehouseId(projectWarehouseId));
    }

    /**
     * 新增项目仓库操作权限
     */
    @PreAuthorize("@ss.hasPermi('pack:project:edit')")
    @Log(title = "项目仓库操作权限", businessType = BusinessType.INSERT)
    @PostMapping("/{projectId}/warehouse/{warehouseId}/operation")
    public AjaxResult add(@PathVariable("projectId") Long projectId, @PathVariable("warehouseId") Long warehouseId, @RequestBody PackProjectWarehouseOperation operation)
    {
        operation.setProjectId(projectId);
        operation.setWarehouseId(warehouseId);
        return toAjax(packProjectWarehouseOperationService.insertPackProjectWarehouseOperation(operation));
    }

    /**
     * 修改项目仓库操作权限
     */
    @PreAuthorize("@ss.hasPermi('pack:project:edit')")
    @Log(title = "项目仓库操作权限", businessType = BusinessType.UPDATE)
    @PutMapping("/{projectId}/warehouse/{warehouseId}/operation")
    public AjaxResult edit(@PathVariable("projectId") Long projectId, @PathVariable("warehouseId") Long warehouseId, @RequestBody PackProjectWarehouseOperation operation)
    {
        operation.setProjectId(projectId);
        operation.setWarehouseId(warehouseId);
        return toAjax(packProjectWarehouseOperationService.saveOrUpdateProjectWarehouseOperation(operation));
    }

    /**
     * 删除项目仓库操作权限
     */
    @PreAuthorize("@ss.hasPermi('pack:project:edit')")
    @Log(title = "项目仓库操作权限", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectId}/warehouse/{warehouseId}/operation")
    public AjaxResult remove(@PathVariable("projectId") Long projectId, @PathVariable("warehouseId") Long warehouseId)
    {
        PackProjectWarehouseOperation operation = packProjectWarehouseOperationService.selectPackProjectWarehouseOperationByProjectAndWarehouse(projectId, warehouseId);
        if (operation != null) {
            return toAjax(packProjectWarehouseOperationService.deletePackProjectWarehouseOperationByProjectWarehouseId(operation.getProjectWarehouseId()));
        }
        return AjaxResult.success();
    }
} 